package cn.luischen.controller.admin;

import cn.luischen.constant.LogActions;
import cn.luischen.constant.Types;
import cn.luischen.controller.BaseController;
import cn.luischen.dto.cond.ContentCond;
import cn.luischen.dto.cond.MetaCond;
import cn.luischen.exception.BusinessException;
import cn.luischen.model.ContentDomain;
import cn.luischen.model.MetaDomain;
import cn.luischen.service.content.ContentService;
import cn.luischen.service.log.LogService;
import cn.luischen.service.meta.MetaService;
import cn.luischen.utils.APIResponse;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import java.lang.reflect.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import java.util.Map;
import java.util.List;
import com.unitspirit.runtime.*;

/**
 * The class contains tests for the class cn.luischen.controller.admin.ArticleController.
 *
 * @generatedBy UnitSpirit CreateTemplateTestFile4
 * @version 1.0.9.11 
 */
@PowerMockIgnore({ "javax.management.*" })
@RunWith(PowerMockRunner.class)
@PrepareForTest({ cn.luischen.model.ContentDomain.class,
		cn.luischen.utils.APIResponse.class })
public class ArticleController_publishArticle_WGTest {
	@Rule
	public ExpectedException unitspirit_thrown = ExpectedException.none();

	/**
	 * 测试方法初始化.
	 * 
	 * @throws Exception 
	 *         if the initialization fails for some reason 
	 *  
	 * @generatedBy UnitSpirit at 2021-12-08 11:01:09
	 */
	@org.junit.Before
	public void setUp() throws Exception {
		try {
			GlobalUnitInit.init();
			MockitoAnnotations.initMocks(this);
			ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	@InjectMocks
	cn.luischen.controller.admin.ArticleController unitspirit_fixture;

	@Mock
	cn.luischen.service.content.ContentService mock_ContentService;
	@Mock
	cn.luischen.service.meta.MetaService mock_MetaService;
	@Mock
	cn.luischen.service.log.LogService mock_LogService;

	/**
	 * @date 2021-12-08 11:01:10
	 * @see cn.luischen.controller.admin.ArticleController#publishArticle
	 * @category null  
	 * @author UnitSpirit   
	 */
	@Test
	public void test_publishArticle_1001_002812_810_2_01() throws Throwable {
		//被测函数参数定义
		javax.servlet.http.HttpServletRequest HttpServletRequest_p_0 = Mockito
				.mock(javax.servlet.http.HttpServletRequest.class);
		String String_p_1 = "国庆测试1";
		String String_p_2 = null;
		String String_p_3 = null;
		String String_p_4 = "国庆测试1";
		String String_p_5 = "post";
		String String_p_6 = "publish";
		String String_p_7 = "国庆测试1";
		String String_p_8 = "默认分类";
		Boolean Boolean_p_9 = true;
		//成员变量设置

		//返回值定义 
		String result_expected = "{\"code\":\"success\"}";

		cn.luischen.model.ContentDomain mock_sub_caller_ContentDomain12 = PowerMockito
				.mock(cn.luischen.model.ContentDomain.class);
		String Stringmock11_0 = "国庆测试1";
		String Stringmock10_0 = null;
		String Stringmock9_0 = null;
		String Stringmock8_0 = "国庆测试1";
		String Stringmock7_0 = "post";
		String Stringmock6_0 = "publish";
		String Stringmock5_0 = "国庆测试1";
		String Stringmock4_0 = "默认分类";
		Integer Integermock3_0 = 1;
		cn.luischen.model.ContentDomain ContentDomainmock2_0 = JSON
				.parseObject(
						"{\"allowComment\":1,\"categories\":\"默认分类\",\"title\":\"国庆测试1\",\"type\":\"post\",\"content\":\"国庆测试1\",\"cid\":27,\"status\":\"publish\",\"tags\":\"国庆测试1\"}",
						cn.luischen.model.ContentDomain.class);
		PowerMockito.mockStatic(cn.luischen.utils.APIResponse.class);
		cn.luischen.utils.APIResponse mock_result_APIResponse1 = JSON
				.parseObject("{\"code\":\"success\"}",
						cn.luischen.utils.APIResponse.class);

		PowerMockito.whenNew(cn.luischen.model.ContentDomain.class)
				.withNoArguments().thenReturn(mock_sub_caller_ContentDomain12);
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setTitle(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setTitlePic(Mockito.any());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setSlug(Mockito.any());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setContent(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setType(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setStatus(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setTags(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setCategories(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_ContentDomain12)
				.setAllowComment(Mockito.anyInt());
		PowerMockito.doNothing().when(mock_ContentService)
				.addArticle(Mockito.any(cn.luischen.model.ContentDomain.class));
		PowerMockito.when(cn.luischen.utils.APIResponse.success()).thenReturn(
				mock_result_APIResponse1);

		cn.luischen.utils.APIResponse unitspirit_result = unitspirit_fixture
				.publishArticle(HttpServletRequest_p_0, String_p_1, String_p_2,
						String_p_3, String_p_4, String_p_5, String_p_6,
						String_p_7, String_p_8, Boolean_p_9);
		cn.luischen.utils.APIResponse obj_expected = JSON.parseObject(
				result_expected, cn.luischen.utils.APIResponse.class);
		UnitAssert.assertEquals(
				UnitSpiritFastJsonUtil.getJsonString2(obj_expected),
				UnitSpiritFastJsonUtil.getJsonString2(unitspirit_result));
	}
  /**
  * @date 2021-12-08 11:01:10
  * @see cn.luischen.controller.admin.ArticleController#publishArticle
  * @category null  
  * @author UnitSpirit   
  */
  @Test
  public void test_publishArticle_1207_113850_557_2_01() throws Throwable {
    //被测函数参数定义
    javax.servlet.http.HttpServletRequest HttpServletRequest_p_0 = Mockito.mock(javax.servlet.http.HttpServletRequest.class);
    String String_p_1 = "123";
    String String_p_2 = null;
    String String_p_3 = null;
    String String_p_4 = "123";
    String String_p_5 = "post";
    String String_p_6 = "publish";
    String String_p_7 = "123";
    String String_p_8 = "默认分类";
    Boolean Boolean_p_9 = true;
  //成员变量设置


    //返回值定义 
    String result_expected = "{\"code\":\"success\"}";

    cn.luischen.model.ContentDomain mock_sub_caller_ContentDomain12 = PowerMockito.mock(cn.luischen.model.ContentDomain.class);
    String Stringmock11_0 = "123";
    String Stringmock10_0 = null;
    String Stringmock9_0 = null;
    String Stringmock8_0 = "123";
    String Stringmock7_0 = "post";
    String Stringmock6_0 = "publish";
    String Stringmock5_0 = "123";
    String Stringmock4_0 = "默认分类";
    Integer Integermock3_0 = 1;
    cn.luischen.model.ContentDomain ContentDomainmock2_0 =  JSON.parseObject("{\"allowComment\":1,\"categories\":\"默认分类\",\"title\":\"123\",\"type\":\"post\",\"content\":\"123\",\"cid\":27,\"status\":\"publish\",\"tags\":\"123\"}",cn.luischen.model.ContentDomain.class);
    PowerMockito.mockStatic(cn.luischen.utils.APIResponse.class);
    cn.luischen.utils.APIResponse mock_result_APIResponse1 =  JSON.parseObject("{\"code\":\"success\"}",cn.luischen.utils.APIResponse.class);

    PowerMockito.whenNew(cn.luischen.model.ContentDomain.class).withNoArguments().thenReturn( mock_sub_caller_ContentDomain12);
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setTitle(anyString());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setTitlePic(Mockito.any());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setSlug(Mockito.any());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setContent(anyString());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setType(anyString());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setStatus(anyString());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setTags(anyString());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setCategories(anyString());
    PowerMockito.doNothing().when( mock_sub_caller_ContentDomain12).setAllowComment(Mockito.anyInt());
    PowerMockito.doNothing().when(mock_ContentService).addArticle(Mockito.any(cn.luischen.model.ContentDomain.class ));
    PowerMockito.when(cn.luischen.utils.APIResponse.success()).thenReturn( mock_result_APIResponse1);

    cn.luischen.utils.APIResponse  unitspirit_result =  unitspirit_fixture.publishArticle(HttpServletRequest_p_0,String_p_1,String_p_2,String_p_3,String_p_4,String_p_5,String_p_6,String_p_7,String_p_8,Boolean_p_9);
    cn.luischen.utils.APIResponse obj_expected = JSON.parseObject(result_expected,cn.luischen.utils.APIResponse.class);
    UnitAssert.assertEquals(UnitSpiritFastJsonUtil.getJsonString2(obj_expected),UnitSpiritFastJsonUtil.getJsonString2(unitspirit_result));
  }
}